//
//  Button.swift
//  MYModule
//
//  Created by 李然 on 2022/7/19.
//

import UIKit

open class Button: UIButton {

    public override init(frame: CGRect) {
        super.init(frame: frame)
        makeUI()
    }
    
    required public init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    public var cornerRadius: CGFloat = 0.0 {
        didSet {
            self.updateProperties()
        }
    }
    public var shadowColor: UIColor = UIColor.clear {
        didSet {
            self.updateProperties()
        }
    }
    public var shadowOffset: CGSize = CGSize(width: 0.0, height: 0.0) {
        didSet {
            self.updateProperties()
        }
    }
    public var shadowRadius: CGFloat = 0.0 {
        didSet {
            self.updateProperties()
        }
    }
    public var shadowOpacity: CGFloat = 1 {
        didSet {
            self.updateProperties()
        }
    }
    
    fileprivate func updateProperties() {
 
        self.layer.cornerRadius = self.cornerRadius
        self.layer.shadowColor = self.shadowColor.cgColor
        self.layer.shadowOffset = self.shadowOffset
        self.layer.shadowRadius = self.shadowRadius
        self.layer.shadowOpacity = Float(self.shadowOpacity)
    }

    
    open func makeUI() {
        layer.masksToBounds = true
        titleLabel?.lineBreakMode = .byWordWrapping
        updateUI()
    }

    open func updateUI() {
        setNeedsDisplay()
    }
}
